package com.sky.controller.user;

import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import com.sky.websocket.WebSocketServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userOrderController")
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "用户订单接口")
public class OrderController {
    @Autowired
    private OrderService orderService;


    @ApiOperation(value = "用户下单")
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        OrderSubmitVO orderSubmitVO = orderService.submit(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    //TODO 自己写的功能没有测试，支付功能写了，但没完全写
    @ApiOperation(value = "查询历史订单")
    @GetMapping("/historyOrders")
    public Result<PageResult> selectPage(int page, int pageSize, Integer status) {
        PageResult orders = orderService.selectPage(page, pageSize, status);
        return Result.success(orders);

    }

    @ApiOperation(value = "查询订单详情")
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> selectOrderDetail(@PathVariable("id") Long id) {
        OrderVO orderVO = orderService.selectOD(id);
        return Result.success(orderVO);
    }


    @ApiOperation(value = "取消订单")
    @PutMapping("/cancel/{id}")
    public Result cancel(@PathVariable("id") Long id) {
        orderService.cancel(id);
        return Result.success();

    }


    @ApiOperation(value = "再来一单")
    @PostMapping("/repetition/{id}")
    public Result repetition(@PathVariable Long id) {
        orderService.repetiton(id);
        return Result.success();
    }


    @ApiOperation(value = "订单支付")
    @PutMapping("/payment")
    public Result pay(@RequestBody OrdersPaymentDTO ordersPaymentDTO) {

        orderService.pay(ordersPaymentDTO);
        return Result.success();
    }


    @ApiOperation(value = "催单")
    @GetMapping("/reminder/{id}")
    public Result reminder(@PathVariable Long id) {

        orderService.reminder(id);
        return Result.success();
    }
}
